//
//  JMPlatform.m
//  JMLibrary
//
//  Created by zhengxianda on 2018/7/24.
//

#import "JMPlatform.h"

@implementation JMPlatform

- (NSString *)errorDomain{
    return @"JMShare";
}

- (void)registerApp:(NSString *)appId{
    
}

- (BOOL)handleOpenURL:(NSURL *)url{
    return YES;
}

- (void)shareToChannel:(JMShareChannel)channel
         messageObject:(JMShareMessageObject *)messageObject
               handler:(JMShareRequestHandler)handler{
    self.handler = handler;
}

- (NSString *)errorMsgWithCode:(int)code{
    return @"";
}

- (void)callHandlerWithCode:(int)errorCode{
    BOOL success = errorCode == 0;
    NSError * error = success ? nil : [NSError errorWithDomain:self.errorDomain code:errorCode userInfo:@{@"msg": [self errorMsgWithCode:errorCode]}];
    [self callHandlerWithError:error];
}

- (void)callHandlerWithError:(NSError *)error{
    if (self.handler) {
        self.handler(error);
        self.handler = nil;
    }
}

@end
